package com.whz.governance.http.feign;

import com.alibaba.cloud.sentinel.feign.SentinelFeignAutoConfiguration;
import com.google.common.collect.Maps;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.env.EnvironmentPostProcessor;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.MapPropertySource;

import java.util.Map;

/**
 * feign.sentinel.enabled=true 启动feign的fallback
 * <p>
 * {@link SentinelFeignAutoConfiguration}
 * </p>
 *
 * @author whz
 */
public class FeignFallBackConfig implements EnvironmentPostProcessor {
    @Override
    public void postProcessEnvironment(final ConfigurableEnvironment environment, final SpringApplication application) {
        Map<String, Object> map = Maps.newHashMap();
        map.put("feign.sentinel.enabled", "true");
        MapPropertySource source = new MapPropertySource("TONGYU-ENABLE-FEIGN-SENTINEL", map);
        environment.getPropertySources().addLast(source);
    }
}